package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "营业状态")
public class ShopController {
    public static final String KEY = "SHOP_STATUS";
    @Autowired
    RedisTemplate redisTemplate;

    /**
     * 设置营业状态管理端
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("营业状态变更")
    public Result statusSetting(@PathVariable Integer status){
        log.info("设置店铺的营业状态为：{}",status == 1 ? "营业中" : "打烊中");
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }

    /**
     * 营业状态查询管理端
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("营业状态管理端查询")
    public Result statusGet(){
        Integer o = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("设置店铺的营业状态为：{}",o == 1 ? "营业中" : "打烊中");
        return Result.success(o);
    }

}
